const _=require('underscore');
const getQueryString=require('./getQueryString');

module.exports=(query,p,total)=>{
    if(total<=1)return false;

    let page={
        first:getQueryString(query,{p:1}),
        last:getQueryString(query,{p:total}),
        curr:p,
        total:total,
        list:_.times(total,i=>{
            return {
                num:i+1,
                isCurr:i+1==p,
                query:getQueryString(query,{p:i+1})
            }
        }),
        isFirst:1==p,
        isLast:total==p
    };

    if(!page.isFirst){
        page.prev=getQueryString(query,{p:p-1});
    }
    if(!page.isLast){
        page.next=getQueryString(query,{p:p+1});
    }
    return page;
};